<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/resources/include/header.jsp"%>
<html>
<head>
<title>${applicationScope.__SYSTEM_ATTRIBUTE__.page_title.content }
	- 新增用户</title>
<base target="_self" />
<%@ include file="/resources/include/plugin.jsp"%>
<%@ include file="/resources/include/extra.jsp"%>
<style>
.picImg img {
	border: 2px solid gray;
	height: 90px;
}

.imgSetA {
	margin-left: 10px;
	margin-top: 5px;
}
</style>
<script type="text/javascript">
	//定义返回URL
	var goBackUrl = '${pageContext.request.contextPath }/core/system/user';
	//返回
	function goBack(){
		sw.showProcessBar();
		window.location.href = goBackUrl;
	}
	$(function(){
		$('#edit_baseInfo').bind('click', saveBaseInfo);
		var logoPath = '${baseInfo.logo}';
		if(null == logoPath || '' == logoPath) {
			$("#picImg").html('<img src="${pageContext.request.contextPath }/image/default_logo_img.jpg" alt="网站logo">');
		}else {
			$("#picImg").html('<img src="${applicationScope.__SYSTEM_ATTRIBUTE__.source_webapp_file_postion.content }${baseInfo.logo}" alt="网站logo">');
		}
	});
	function saveBaseInfo(){
		if(!confirm('确定保存已编辑信息吗？')){
			return;
		}
		var url = '${pageContext.request.contextPath }/wzgl/baseInfo/edit';
		var params = $("#baseinfoForm").serializeArray();
        params.push({"name": "logo", "value": $("input[name=piclogo]").val()});

		sw.showProcessBar();
		sw.ajaxSubmitForForm(url, params, "piclogo", function(data){
			sw.ajaxSuccessCallback(data, function(){
				userValidator.reset(true);
			});
		});
	}
	//验证图片  
    function preview(file) {
        if (/.+\.(jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG|gif|GIF)/g.test(document.getElementById('piclogo').value)) {
            previewImage(200, 90, file, "picImg");
        } else {
            alert('请选择正确的图片格式（jpg,jpeg,bmp,png,gif）');
            document.getElementById('picture').value = '';
            return false;
        }
    }
  	//预览图片
    function previewImage(MAXWIDTH, MAXHEIGHT, file, divId) {
        var div = document.getElementById(divId);
        if (file.files && file.files[0]) {
            div.innerHTML = '<img id=' + divId + 'imghead >';
            var img = document.getElementById(divId + 'imghead');
            img.onload = function () {
                var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
                img.width = rect.width;
                img.height = rect.height;
                img.style.marginLeft = '0px';
                img.style.marginTop = '5px';
            }
            var reader = new FileReader();
            reader.onload = function (evt) {
                img.src = evt.target.result;
            }
            reader.readAsDataURL(file.files[0]);
        } else {
            file.select();
            div.focus();//file.blur();  
            var src = document.selection.createRange().text;
            div.innerHTML = "<div id=divhead style=\"FILTER:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);width:160px; height:160px\"></div>";
            var newPreview = document.getElementById("divhead");            
            newPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src;  
        }
    }
    /*
     * 设置图片大小宽高
     */
     function clacImgZoomParam(maxWidth, maxHeight, width, height) {
         var param = {top: 0, left: 0, width: width, height: height};
         if (width > maxWidth || height > maxHeight) {
             rateWidth = width / maxWidth;
             rateHeight = height / maxHeight;

             if (rateWidth > rateHeight) {
                 param.width = maxWidth;
                 param.height = Math.round(height / rateWidth);
             } else {
                 param.width = Math.round(width / rateHeight);
                 param.height = maxHeight;
            }
        }

        param.left = Math.round((maxWidth - param.width) / 2);
        param.top = Math.round((maxHeight - param.height) / 2);
        return param;
     }
</script>
</head>
<body>
	<jsp:include page="/core/base/layout/header" />
	<jsp:include page="/core/base/layout/left" />
	<jsp:include page="/core/base/layout/shortcut" />
	<div class="main-container">
		<ul class="breadcrumb">
			<li><a href="${pageContext.request.contextPath }/core/base/home"><i class="fa fa-home"></i>首页</a></li>
			<li><a href="javascript:void(0);"><i class="fa fa-paper-plane-o"></i>网站管理</a></li>
			<li class="active"><a href="javascript:void(0);"><i class="fa fa-file-text-o"></i>基本信息</a></li>
		</ul>
		<div class="panel panel-default">
			<div class="panel-heading">
				<i class="fa fa-pencil"></i>编辑
			</div>
			<div class="panel-body">
				<form:form cssClass="form-horizontal" id="baseinfoForm" modelAttribute="baseInfo" method="post">
				<form:hidden path="id" />
					<div class="form-group">
						<div class="col-sm-9">
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">网站名称：</label>
								<div class="col-sm-4">
									<sw:input path="name" cssClass="form-control" placeholder="请输入网站名称" valid="" 
										validTitle="网站名称" validInfoArea="name_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="name_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">手机号码：</label>
								<div class="col-sm-4">
									<sw:input path="phone" cssClass="form-control" placeholder="请输入手机号码" valid="" 
										validTitle="手机号码" validInfoArea="phone_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="phone_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">咨询电话：</label>
								<div class="col-sm-4">
									<sw:input path="server_phone" cssClass="form-control" placeholder="请输入咨询电话" valid="" 
										validTitle="咨询电话" validInfoArea="serverphone_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="serverphone_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">销售电话：</label>
								<div class="col-sm-4">
									<sw:input path="sale_phone" cssClass="form-control" placeholder="请输入销售电话" valid="" 
										validTitle="销售电话" validInfoArea="salephone_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="salephone_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">邮箱：</label>
								<div class="col-sm-4">
									<sw:input path="email" cssClass="form-control" placeholder="请输入邮箱地址" valid="" 
										validTitle="邮箱地址" validInfoArea="email_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="email_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">传真：</label>
								<div class="col-sm-4">
									<sw:input path="fax" cssClass="form-control" placeholder="请输入传真" valid="" 
										validTitle="传真" validInfoArea="fax_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="fax_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">QQ：</label>
								<div class="col-sm-4">
									<sw:input path="qq" cssClass="form-control" placeholder="请输入QQ号码" valid="" 
										validTitle="QQ号码" validInfoArea="QQ_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="QQ_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">微信：</label>
								<div class="col-sm-4">
									<sw:input path="weichat" cssClass="form-control" placeholder="请输入微信号码" valid="" 
										validTitle="咨微信号码" validInfoArea="weichat_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="weichat_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">公司地址：</label>
								<div class="col-sm-4">
									<sw:input path="location" cssClass="form-control" placeholder="请输入公司地址" valid="" 
										validTitle="公司地址" validInfoArea="location_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="location_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">版权信息：</label>
								<div class="col-sm-4">
									<sw:input path="copyright" cssClass="form-control" placeholder="请输入版权信息" valid="" 
										validTitle="版权信息" validInfoArea="copyright_code_info_area" />
								</div>
								<div class="col-sm-3"><p class="help-block" id="copyright_code_info_area"></p></div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-2 control-label text-right">网站简介：</label>
								<div class="col-sm-7">
									<sw:textarea path="introduction" cssClass="form-control" rows="4" placeholder="请输入网站简介" valid="" validInfoArea="introduction_info_area" />
								</div>
							</div>
						</div>
						
						<!-- 网站logo -->          
                        <div class="col-sm-3">
                            <div class="imgContent">
                                <div class="picImg" id="picImg"></div>
                                <div class="imgSetA">
									<input id="piclogo" name="piclogo" type="file" onchange="preview(this)"/>
                                </div>
                            </div>
                        </div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<sw:button accesskey="S" id="edit_baseInfo" cssClass="btn btn-success"
								value="保存 (S)" icon="save"/>
							<button accesskey="B" type="button" class="btn btn-default"
								onclick="goBack();">
								<i class="fa fa-arrow-circle-left"></i>返回 (B)
							</button>
						</div>
					</div>
				</form:form>
			</div>
		</div>
		<div class="clearfix"></div>
	</div>
</body>
</html>
